package com.puboot.module.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.puboot.common.util.Constants;
import com.puboot.common.util.CoreConst;
import com.puboot.common.util.ResultUtil;
import com.puboot.module.admin.model.BizContact;
import com.puboot.module.admin.model.BizMessage;
import com.puboot.module.admin.model.User;
import com.puboot.module.admin.service.BizContactService;
import com.puboot.module.admin.service.BizMessageService;
import com.puboot.module.admin.vo.base.PageResultVo;
import com.puboot.module.admin.vo.base.ResponseVo;
import lombok.AllArgsConstructor;
import org.apache.shiro.SecurityUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Controller
@RequestMapping("message")
@AllArgsConstructor
public class BizMessageController {

    private final BizMessageService bizMessageService;


    @PostMapping("list")
    @ResponseBody
    public PageResultVo loadMessageList(BizMessage bizMessage, Integer pageNumber, Integer pageSize) {
        IPage<BizMessage> bizMessageIPage = bizMessageService.pageBizMessageAll(bizMessage, pageNumber, pageSize);
        return ResultUtil.table(bizMessageIPage.getRecords(), bizMessageIPage.getTotal());
    }

    @PostMapping("/del")
    @ResponseBody
    public ResponseVo delete(Integer id) {
        return deleteBatch(new Integer[]{id});
    }

    @PostMapping("/batch/delete")
    @ResponseBody
    public ResponseVo deleteBatch(@RequestParam("ids[]") Integer[] ids) {
        int i = bizMessageService.deleteBatch(ids);
        if (i > 0) {
            return ResultUtil.success("删除成功");
        } else {
            return ResultUtil.error("删除失败");
        }
    }
}
